{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b12b4414-d78d-4bb4-834f-ad31c2d48d31",
   "metadata": {},
   "source": [
    "Chapter 05\n",
    "# 列表拆包、打包\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d64feb8a-9b45-4c61-98af-98bcba88dc5b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义列表\n",
    "list_0 = [0, 1, 2, 3, 4, 5, 6, 7, 8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fa782870-c09c-4721-912c-840f992dfda5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8]\n"
     ]
    }
   ],
   "source": [
    "first, *list_rest = list_0\n",
    "print(list_rest) # [1, 2, 3, 4, 5, 6, 7, 8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c8626a19-cc03-49ef-8439-2cdf3c28cb34",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 4, 5, 6, 7, 8]\n"
     ]
    }
   ],
   "source": [
    "first, second, *list_rest = list_0\n",
    "print(list_rest) # [2, 3, 4, 5, 6, 7, 8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fc664f6d-8939-480f-a9ef-ffea521d8b6c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 4, 5, 6, 7]\n"
     ]
    }
   ],
   "source": [
    "first, second, *list_rest, last = list_0\n",
    "print(list_rest) # [2, 3, 4, 5, 6, 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3658fc51-6141-4d2b-9b6e-e5f53d030732",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7]\n"
     ]
    }
   ],
   "source": [
    "first, *list_rest, _ = list_0\n",
    "print(list_rest) # [1, 2, 3, 4, 5, 6, 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "dd27380a-1653-4918-b57b-5ed576a67ca6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8]\n"
     ]
    }
   ],
   "source": [
    "list1 = [1, 2, 3, 4, 5]\n",
    "list2 = [6, 7, 8]\n",
    "# 合并\n",
    "combined_list = [*list1, *list2]\n",
    "print(combined_list) # [1, 2, 3, 4, 5, 6, 7, 8]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
